package com.example.miniodemo.common.config.converter;

import com.example.miniodemo.common.util.PubUtils;
import org.modelmapper.AbstractConverter;
import org.springframework.core.convert.converter.Converter;
import org.springframework.stereotype.Component;

import java.util.UUID;

/**
 * UUID转化处理类
 *
 * @author Lv
 * @date 2022/11/4
 */
@Component
public class StringUUIDConverter extends AbstractConverter<String, UUID> implements Converter<String, UUID> {
    /**
     * 转换方法
     *
     * @param string 转换字符串
     * @return
     */
    @Override
    public UUID convert(String string) {
        if (PubUtils.isEmpty(string)) {
            return null;
        }
        return UUID.fromString(string);
    }
}
